<?php
class BlogCommentsController extends AppController {

	var $name = 'BlogComments';

        function beforeFilter(){
		parent::beforeFilter();
	  	$this->Auth->allowedActions = array('*');

	}

	function index() {
		$this->BlogComment->recursive = 0;
		$this->set('blogComments', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid blog comment', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('blogComment', $this->BlogComment->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->BlogComment->create();
			if ($this->BlogComment->save($this->data)) {
				$this->Session->setFlash(__('The blog comment has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The blog comment could not be saved. Please, try again.', true));
			}
		}
		$blogs = $this->BlogComment->Blog->find('list');
		$users = $this->BlogComment->User->find('list');
		$this->set(compact('blogs', 'users'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid blog comment', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->BlogComment->save($this->data)) {
				$this->Session->setFlash(__('The blog comment has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The blog comment could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->BlogComment->read(null, $id);
		}
		$blogs = $this->BlogComment->Blog->find('list');
		$users = $this->BlogComment->User->find('list');
		$this->set(compact('blogs', 'users'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for blog comment', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->BlogComment->delete($id)) {
			$this->Session->setFlash(__('Blog comment deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Blog comment was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
	function backstage_index() {
		$this->BlogComment->recursive = 0;
		$this->set('blogComments', $this->paginate());
	}

	function backstage_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid blog comment', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('blogComment', $this->BlogComment->read(null, $id));
	}

	function backstage_add() {
		if (!empty($this->data)) {
			$this->BlogComment->create();
			if ($this->BlogComment->save($this->data)) {
				$this->Session->setFlash(__('The blog comment has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The blog comment could not be saved. Please, try again.', true));
			}
		}
		$blogs = $this->BlogComment->Blog->find('list');
		$users = $this->BlogComment->User->find('list');
		$this->set(compact('blogs', 'users'));
	}

	function backstage_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid blog comment', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->BlogComment->save($this->data)) {
				$this->Session->setFlash(__('The blog comment has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The blog comment could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->BlogComment->read(null, $id);
		}
		$blogs = $this->BlogComment->Blog->find('list');
		$users = $this->BlogComment->User->find('list');
		$this->set(compact('blogs', 'users'));
	}

	function backstage_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for blog comment', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->BlogComment->delete($id)) {
			$this->Session->setFlash(__('Blog comment deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Blog comment was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
?>